/**
 * @File   cls_led.c 
 * @Berif  LED类创建
 * @Encode UTF-8
 * @Log    Date         Author     Notes
 *         2021.01.25   Jimmy      first version
 */
#include "rtthread.h"
#include "stm32f4xx.h"
#include "error_type.h"
#include "cls_led.h"

typedef void(*led_init)(void);

/**
 * @brief  实例化对象 
 * @param  init         ：led硬件初始化函数
 * @param  on           ：led开
 * @param  off          ：led关
 * @retval cls_led_s *  ：实例化的led对象
 */
cls_led_s * create_led_control(void * init, void * on, void * off)
{
  cls_led_s * led_cls = RT_NULL;

  if((init == RT_NULL) || (on == RT_NULL) || (off == RT_NULL))
  {
    return RT_NULL;
  }

  led_cls = (cls_led_s *)rt_malloc(sizeof(cls_led_s));

  if(led_cls == RT_NULL)
  {
    return RT_NULL;
  }

  rt_memset((cls_led_s *)led_cls, 0, sizeof(cls_led_s));

  led_cls->init   = (void (*)(void))init;
  led_cls->on     = (void (*)(void))on;
  led_cls->off    = (void (*)(void))off;

  if(led_cls->init != RT_NULL)
  {
    led_cls->init();
  }

  return led_cls;
}

/**
 * @brief  释放实体 
 * @param  cls_led_s *   ：要释放的实体
 * @retval none
 */
void free_led_control(cls_led_s * cls_led)
{
  if(cls_led != RT_NULL)
  {
    rt_free(cls_led);
    cls_led = RT_NULL;
  }  
}


/* End of file */
